#! /usr/bin/env python

VERSION='0.1'
APPNAME='gui'

srcdir = '.'
blddir = 'build'

import sys, re
import waf_dynamo, waf_ddf
import waflib.Options
import TestContext
from build_constants import TargetOS

test_context = None

def init(ctx):
    global test_context
    if 'build' in waflib.Options.commands:
        test_context = TestContext.create_test_context()

def options(opt):
    opt.load('waf_dynamo')

def configure(conf):
    conf.load('waf_dynamo')
    target_os = conf.env['TARGET_OS']

    waf_ddf.configure(conf)

    conf.recurse('src')

    conf.env.append_value('INCLUDES', 'src')
    conf.env['STLIB_DLIB'] = ['dlib', 'mbedtls', 'zip']
    conf.env['STLIB_DDF'] = 'ddf'
    conf.env['STLIB_PARTICLE'] = 'particle'
    conf.env['STLIB_RIG'] = 'rig'
    conf.env['STLIB_SCRIPT'] = 'script'
    conf.env['STLIB_RESOURCE'] = 'resource'
    conf.env['STLIB_EXTENSION'] = 'extension'
    conf.env['STLIB_GAMEOBJECT'] = 'gameobject'
    conf.env['STLIB_GRAPHICS_PROTO'] = ['graphics_proto']

    platform = conf.env['PLATFORM']

    if platform in ("x86_64-macos",):
        conf.env.append_value('LINKFLAGS', ['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'IOKit', '-framework', 'CoreVideo'])
    if target_os == TargetOS.IOS:
        conf.env.append_value('LINKFLAGS', ['-framework', 'UIKit', '-framework', 'OpenGLES', '-framework', 'QuartzCore', '-framework', 'CoreGraphics'])
    if target_os == TargetOS.WINDOWS:
        conf.env.append_value('LINKFLAGS', ['opengl32.lib', 'glu32.lib', 'user32.lib', 'shell32.lib', 'xinput9_1_0.lib'])

    conf.env.append_unique('DEFINES', 'DLIB_LOG_DOMAIN="GUI"')

def build(bld):
    global test_context
    bld.recurse('src')
    TestContext.initialize_test_context(test_context, bld)

def shutdown(self):
    waf_dynamo.run_tests(test_context, valgrind = True)
